package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.TbContentCategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("category")
public class TbContentCategoryController {

    @Reference
    private TbContentCategoryService tbContentCategoryService;

    @RequestMapping("categoryInfo")
    public String categoryInfo(){
        return "admin/content_category";
    }

    @RequestMapping("getCategoryList")
    @ResponseBody
    public Result getCategoryList(){
        List<TbContentCategory> list = tbContentCategoryService.getCategoryList();
        return Result.build(ConstantEnum.SUCCESS).setResult(list);
    }

    @RequestMapping("insertCategory")
    @ResponseBody
    public Result insertCategory(TbContentCategory tbContentCategory){
        tbContentCategoryService.insertCategory(tbContentCategory);
        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("updateCategory")
    @ResponseBody
    public Result updateCategory(Long id){
        TbContentCategory category = tbContentCategoryService.updateCategory(id);
        return Result.build(ConstantEnum.SUCCESS).setResult(category);
    }

    @RequestMapping("updateCategoryInfo")
    @ResponseBody
    public Result updateCategoryInfo(TbContentCategory tbContentCategory){
        tbContentCategoryService.updateCategoryInfo(tbContentCategory);
        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("deleteCatInfo")
    @ResponseBody
    public Result deleteCatInfo(@RequestParam("ids") Long[] ids){
        tbContentCategoryService.deleteCatInfo(ids);
        return Result.build(ConstantEnum.SUCCESS);
    }

}
